<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>百商汇</title>
	<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0,minimum-scale = 1.0,user-scalable = no,width = device-width">
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" type="text/css" href="../csses/partner.css">
	<script type="text/javascript" src="../lib/jquery-1.10.1.min.js"></script>
</head>
<body>
	<div class="partner_title">
		成为合伙人
		<img src="../image/back.png" onclick="goBack()">
	</div>
	<div class="partner_box">
		<ul class="ul">
			<li>
				<span>合伙人类别</span>
				<input type="text" placeholder="请选择合伙人类别" readonly="true" id="choose"></input>
			</li>
			<li>
				<span>地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;区</span>
				<input type="text" placeholder="请选择您所在的地区" readonly="true" id="area"></input>
			</li>
		</ul>
		<p class="p1">
			公司转账信息如下：<br/>
			公司名称：跃南互联网金融信息服务（上海）有限公司<br/>
			账号及开户行：11015099671004<br/>
			平安银行上海交易所支行
		</p>
		<button class="submitBtn">确认</button>
		<p class="agreement">确认即表示同意<a href="partnerAgree.html">《百商汇合伙人合作协议》</a></p>
		<div class="hidden_box">
			<ul class="partnerBox">
				<li class="choosePartner">请选择合伙人类别</li>
				<ul class="details">
					<li class="1">全国合伙人 (￥5,000,000)</li>
					<li class="2">省级合伙人 (￥1,000,000)</li>
					<li class="3">市级合伙人 (￥300,000)</li>
					<li class="4">县级合伙人 (￥50,000)</li>
				</ul>
			</ul>
		</div>
	</div>
	<div class="province">
		<div class="provinceTitle">
			请选择
			<img src="../image/back.png">
		</div>
		<div id="provinceList">
			<ul>

			</ul>
		</div>
	</div>
	<div class="city">
		<div class="cityTitle">
			请选择
			<img src="../image/back.png">
		</div>
		<div id="cityList">
			<ul></ul>
		</div>
	</div>
	<div class="county">
		<div class="countyTitle">
			请选择
			<img src="../image/back.png">
		</div>
		<div id="countyList">
			<ul></ul>
		</div>
	</div>
	<div id="remindBox"></div>
	<script type="text/javascript" src="../lib/flexible.js"></script>
	<script type="text/javascript" src="../lib/Iscroll-I.js"></script>
	<script type="text/javascript">
		function remind(message){
			$('#remindBox').css('display','block').text(message);
			setTimeout(function(){
				$('#remindBox').css('display','none');
			},1500)
		}

		var $hidden_box = $('.hidden_box');
		$('#choose').click(function(){
			if($('.submitBtn').attr('disabled') == undefined){
				$hidden_box.css('display','block');
			}else{
				remind('信息审核中...');
			}
		});

		$('.details li').click(function(){
			sessionStorage.partnerText = $(this).text();
			$('#choose').attr('value',$(this).text());
			sessionStorage.partnerLevelNum = $(this).attr('class');
			$hidden_box.css('display','none');
		});
		
		$('#area').click(function(){
			if($('.submitBtn').attr('disabled') == undefined){
				$('.province').css('display','block').addClass('first');
				$('.province img').click(function(){
					$('.province').css('display','none');
				})
				var myScroll;
				myScroll = new IScroll('#provinceList', { 
	        		probeType: 3, 
	        		mouseWheel: true,
	        		bounce: false,
	        		click:true
	        	});
	        	document.body.style.overflow = 'hidden';
				$.ajax({
					type : 'post',
					url : '/api/v1/region/list',
					data : {
						paramStr : "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "','pid':'" + 1 + "'}"
					},
					dataType : 'json',
					timeout : 3000,
					success : function (data) {
						if(data.code == 200){
							var obj = JSON.parse(data.data);
							var infoList = obj.info;
							$('#provinceList ul').html('')
							var $ul = $('#provinceList ul');
							for (var i in infoList) {
			                	$('<li provinceId='+infoList[i]["id"]+'>'+infoList[i]["name"]+'</li>').appendTo($ul);
			                }
			                myScroll.refresh();
			                $('#provinceList ul li').click(function(){
			                	sessionStorage.provinceId = $(this).attr('provinceId');
			                	sessionStorage.provinceName = $(this).text();
			                	$('.province').css('display','none').removeClass('first');
			                	$('.city').css('display','block').addClass('first');
			                	$('.city img').click(function(){
			                		$('.city').css('display','none');
			                		$('.province').css('display','block');
			                	})
			                	var myScroll;
								myScroll = new IScroll('#cityList', { 
					        		probeType: 3,
					        		mouseWheel: true,
					        		bounce: false,
					        		click:true
					        	});
					        	document.body.style.overflow = 'hidden';
					        	$.ajax({
					        		type : 'post',
									url : '/api/v1/region/list',
									data : {
										paramStr : "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "','pid':'" + sessionStorage.provinceId + "'}"
									},
									dataType : 'json',
									timeout : 3000,
									success : function(data){
										if(data.code == 200){
											var obj = JSON.parse(data.data);
											var infoList = obj.info;
											$('#cityList ul').html('');
											var $ul = $('#cityList ul');
											for (var i in infoList) {
							                	$('<li cityId='+infoList[i]["id"]+'>'+infoList[i]["name"]+'</li>').appendTo($ul);
							                }
							                myScroll.refresh();
							                $('#cityList ul li').click(function(){
							                	sessionStorage.cityId = $(this).attr('cityId');
							                	sessionStorage.cityName = $(this).text();
							                	$('.city').css('display','none').removeClass('first');
							                	$('.county').css('display','block').addClass('first');
							                	$('.county img').click(function(){
							                		$('.county').css('display','none');
							                		$('.city').css('display','block');
							                	});
							                	var myScroll;
												myScroll = new IScroll('#countyList', { 
									        		probeType: 3, 
									        		mouseWheel: true,
									        		bounce: false,
									        		click:true
									        	});
									        	document.body.style.overflow = 'hidden';
									        	$.ajax({
									        		type : 'post',
													url : '/api/v1/region/list',
													data : {
														paramStr : "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "','pid':'" + sessionStorage.cityId + "'}"
													},
													dataType : 'json',
													timeout : 3000,
													success : function(data){
														if(data.code == 200){
															var obj = JSON.parse(data.data);
															var infoList = obj.info;
															$('#countyList ul').html('');
															var $ul = $('#countyList ul');
															for (var i in infoList) {
											                	$('<li countyId='+infoList[i]["id"]+'>'+infoList[i]["name"]+'</li>').appendTo($ul);
											                }
											                myScroll.refresh();
											                $('#countyList ul li').click(function(){
											                	sessionStorage.countyId = $(this).attr('countyId');
											                	sessionStorage.countyName = $(this).text();
											                	$('.county').css('display','none').removeClass('first');
											                	$('#area').val(sessionStorage.provinceName + ' ' + sessionStorage.cityName + ' ' + sessionStorage.countyName);
											                });
										                }
													},
													error : function (xhr,type,errorThrown) {
														// alert('不知道出了什么错...');
													}
									        	});
							                });
						                }
									},
									error : function (xhr,type,errorThrown) {
										// alert('不知道出了什么错...');
									}
					        	});
			                });
		                }
					},
					error : function (xhr,type,errorThrown) {
						// alert('不知道出了什么错...');
					}
				});
			}else{
				remind('信息审核中...');
			}
		});
		
		

		$('.submitBtn').click(function(){
			var $partner = $('#choose').val();
			var $area = $('#area').val();
			if(!$partner){
				remind('请选择合伙人类别');
			}else if(!$area){
				remind('请选择您所在的地区');
			}else{
				$('.submitBtn').attr('disabled',true).css('background','#ccc');
				$('#choose').attr('readonly',true).val($partner);
				$('#area').attr('readonly',true).val($area);
				$.ajax({
					type : 'post',
					url : '/api/v1/partner/save',
					data : {
						paramStr : "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "','partnerLevel':'" + sessionStorage.partnerLevelNum + "','province':'" + sessionStorage.provinceId + "','city':'" + sessionStorage.cityId + "','area':'" + sessionStorage.countyId + "'}"
					},
					dataType : 'json',
					timeout : 3000,
					success : function (data) {
						remind(data.message);
						if(data.code == 200){
							$('.submitBtn').attr('disabled',true).css('background','#ccc');
							setTimeout(function(){
								goBack();
							},1500);
						}
					},
					error : function (xhr,type,errorThrown) {
						alert('不知道出了什么错...');
					}
				});
			}
		});

		function goBack(){
			window.history.back();
		}
	</script>
</body>
</html>